package com.autodesk.utilitydesign;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

public class ExpandableAdapter extends BaseExpandableListAdapter {

	private Activity activity;
	private List<String> groups = new ArrayList<String>();
	private List<List<Feature>> childs = new ArrayList<List<Feature>>();
	
	public ExpandableAdapter(Activity activity){
		this.activity = activity;
		groups.add("Pole");
		List<Feature> l = new ArrayList<Feature>();
		l.add(new Feature("WP307",1001));
		childs.add(l);
		
	}
	public Object getChild(int groupPosition, int childPosition) {
		childs.get(groupPosition).get(childPosition); 
		return null;
	}

	public long getChildId(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return childPosition;
	}

	public View getChildView(int groupPosition, int childPosition,  
            boolean isLastChild, View convertView, ViewGroup parent) {
		String modelName = childs.get(groupPosition).get(childPosition).getModelName();  
        return getGenericView(modelName); 
	}

	public int getChildrenCount(int groupPosition) {
		// TODO Auto-generated method stub
		return childs.get(groupPosition).size();  

	}

	public Object getGroup(int groupPosition) {
		// TODO Auto-generated method stub
		return groups.get(groupPosition); 
	}

	public int getGroupCount() {
		// TODO Auto-generated method stub
		return groups.size();
	}

	public long getGroupId(int groupPosition) {
		// TODO Auto-generated method stub
		return groupPosition;
	}

	public View getGroupView(int groupPosition, boolean isExpanded,  
            View convertView, ViewGroup parent) {
		String string = groups.get(groupPosition);  
        return getGenericView(string);  
	}

	public boolean hasStableIds() {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean isChildSelectable(int arg0, int arg1) {
		// TODO Auto-generated method stub
		return false;
	}
	
    public TextView getGenericView(String string)  
    {  
        // Layout parameters for the ExpandableListView   
        AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams(  
                ViewGroup.LayoutParams.FILL_PARENT, 64);  
        TextView text = new TextView(activity);  
        text.setLayoutParams(layoutParams);  
        // Center the text vertically   
        text.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);  
        // Set the text starting position   
        text.setPadding(100, 0, 0, 0);  
        text.setText(string);  
        return text;  
    } 

}
